BigDFT.Fragments module

This module contains data structures for describing fragments. Fragments are orders lists of atoms.

distance(i, j, cell=None)[source]

Distance between fragments, defined as distance between centroids (bohr).

Parameters:
Returns:

the distance between centroids.

Return type:

(float)

pairwise_distance(i, j, cell=None)[source]

Distance between fragments as defined by their two nearest atoms (bohr).

Parameters:
Returns:

the pairwise distance between fragments.

Return type:

(float)

lineup_fragment(frag)[source]

Align the principal axis of inertia of the fragments along the coordinate axis. Also shift the fragment such as its centroid is zero.

Parameters:

(BigDFT.Fragments.Fragment) – the fragment to transform.

Returns:

the transformed fragment.

Return type:

(BigDFT.Fragments.Fragment)

class RotoTranslation(frag1, frag2)[source]

Define a transformation which can be applied to a fragment. This rotation is defined by giving this class two fragments, and the rototranslation between those fragments is automatically computed.

Parameters:
dot(frag)[source]

Apply the rototranslations on a fragment.

Parameters:

frag (BigDFT.Fragments.Fragment) – the fragment to rototranslate.

Returns:

the rototranslated fragment.

Return type:

(BigDFT.Fragments.Fragment)

invert()[source]

Computes the inverse rototranslation.

class Translation(t)[source]

This class defines a simple translation.

Parameters:

t (list) – the vector describing the translation.

class Rotation(R)[source]

This class defines a simple rotation.

Parameters:

t (list) – the vector describing the rotation.

interpolate_fragments(A, B, steps, extrapolation_steps=0)[source]

Given two fragments A and B, this generates a list of Fragments that interpolate between A and B in a specified number of steps.

Parameters:
Returns:

a list of fragments interpolating between A and B including A and B.

Return type:

(list)

class Fragment(atomlist=None, xyzfile=None, posinp=None, astruct=None, system=None)[source]

A fragment is a list of atoms in a system. Fragment might have quantities associated to it, like its electrostatic multipoles (charge, dipole, etc.) and also geometrical information (centroids, principla axis etc.). A Fragment might also be rototranslated and combined with other moieteies to form a BigDFT.Systems.Systems.

Parameters:
  • atomlist (list) – list of atomic dictionaries defining the fragment

  • xyzfile (BigDFT.IO.XYZReader) – an XYZ file to read from.

  • posinp (dict) – the posinp style dictionary from a logfile/input file.

  • astruct (dict) – a BigDFT atomic structure style dictionary.

  • system (BigDFT.Systems.System) – a BigDFT system, esssentially this reduces many fragments into a single fragment.

Todo

Define and describe if this API is also suitable for solid-state fragments

serialize(name, units='bohr')[source]

Transform the fragment in a list that can be employed for the construction of dataframes or pandas series.

Parameters:
  • name (str) – the name of the fragment

  • units (str) – the units for the positions

Returns:

the serialized fragment

Return type:

list

property centroid

The center of a fragment. Returned in bohr and without regard to unit cell.

get_centroid(cell=None, units='bohr')[source]

The center of a fragment, with options for units and UnitCell.

Parameters:
  • cell (BigDFT.UnitCells.UnitCell) – the cell this fragment is contained in. Minimum image convention will be enforced.

  • units (str) – units of the centroid to be returned.

center_of_charge()[source]

The charge center which depends both on the position and net charge of each atom.

property q0

Provides the global monopole of the fragments given as a sum of the monopoles of the atoms.

d0(center=None)[source]

Fragment dipole, calculated only from the atomic charges.

Parameters:

center (list) – the center of charge of the fragment. If this is not present, the centroid is used.

d1(center=None)[source]

Fragment dipole including the atomic dipoles.

Parameters:

center (list) – the center of charge of the fragment. If this is not present, the centroid is used.

ellipsoid(center=0.0)[source]

Todo: define the ellipsoid.

get_external_potential(units='bohr', charge_offset=False)[source]

Transform the fragment information into a dictionary ready to be put as an external potential.

Parameters:

units (str) – the units of the external potential.

Returns:

a dictionary describing the external potential for use in an input file.

Return type:

(dict)

get_net_force()[source]

Returns the net force on a fragment in Ha/Bohr.

Returns:

(list) Three values which describe the net force.

qcharge()[source]

The net charge on a fragment.

property nel

The number of valence electrons of the atoms of the fragment

rotate_on_axis(angle, axis, centroid=None, units='radians')[source]

Rotate a fragment along a specific axis.

Parameters:
  • angle (float) – angle to rotate along the axis.

  • axis (list) – a list of floats defining the vector to rotate along.

  • centroid (lismatt) – a list of floats defining the center from which the axis comes out. If not specified, we pick the centroid of the fragment.

  • units (str) – either radians or degrees.

rotate(x=None, y=None, z=None, units='radians')[source]

Rotate the fragment.

Parameters:
  • x (float) – angle to rotate on the x axis.

  • y (float) – angle to rotate on the y axis.

  • z (float) – angle to rotate on the z axis.

  • units (str) – either radians or degrees.

translate(vec)[source]

Translate the fragment along the vector provided.

Parameters:

vec (list) – a list of x, y, z values describing the translation (AU).

rmsd(reference)[source]

Calculate the Reduced Mean Square displacement with a reference fragment.

_example()[source]

The following is an example of module usage:

"""Example of using fragments"""
from BigDFT.IO import XYZReader, XYZWriter
from copy import deepcopy

safe_print("Read in an xyz file and build from a list.")
atom_list = []
with XYZReader("SiO") as reader:
    for at in reader:
        atom_list.append(at)
frag1 = Fragment(atomlist=atom_list)
for at in frag1:
    safe_print(at.sym, at.get_position())
safe_print("Centroid", frag1.centroid)
safe_print()

safe_print("Build from an xyz file directly.")
reader = XYZReader("Si4")
frag2 = Fragment(xyzfile=reader)
for at in frag2:
    safe_print(at.sym, at.get_position())
safe_print()

safe_print("We can combine two fragments with +=")
frag3 = deepcopy(frag1)
frag3 += frag2
for at in frag3:
    safe_print(at.sym, at.get_position())
safe_print("Length of frag3", len(frag3))
safe_print()

safe_print("Since we can iterate easily, we can also write easily.")
with XYZWriter("test.xyz", len(frag3), "angstroem") as writer:
    for at in frag3:
        writer.write(at)
with open("test.xyz") as ifile:
    for line in ifile:
        safe_print(line)
safe_print()

safe_print("We can also extract using the indices")
safe_print(dict(frag3[0]))
sub_frag = frag3[1:3]
for at in sub_frag:
    safe_print(dict(at))
safe_print()